package com.yiwenup.leetcode.site;

import java.util.HashMap;
import java.util.Map;

/**
 * 文件描述
 *
 * @Project struct-algorithm
 * @Package com.yiwenup.leetcode.site
 * @Author yiwenup
 * @Date 2024-12-15 22:23:07
 * @Description https://leetcode.cn/problems/two-sum/description/
 */
public class No0001 {
    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> tmp = new HashMap<>();

        for(int i = 0; i< nums.length; i++) {
            if(tmp.containsKey(target - nums[i])) {
                return new int[]{tmp.get(target - nums[i]), i};
            }
            tmp.put(nums[i], i);
        }
        return new int[2];
    }
}
